home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 February (DVD) / PCWorld_2008-02_DVD.iso / v cisle / PHP / PHP.exe / EasyPHP-2.0b1-setup.exe / {app} / sqlitemanager / include / JSCookMenu.js < prev    next >
Encoding:
JavaScript  |  2006-04-18  |  22.4 KB  |  953 lines

  1. /*
  2.     JSCookMenu v1.3.  (c) Copyright 2002-2004 by Heng Yuan
  3.  
  4.     Permission is hereby granted, free of charge, to any person obtaining a
  5.     copy of this software and associated documentation files (the "Software"),
  6.     to deal in the Software without restriction, including without limitation
  7.     the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8.     and/or sell copies of the Software, and to permit persons to whom the
  9.     Software is furnished to do so, subject to the following conditions:
  10.  
  11.     The above copyright notice and this permission notice shall be included
  12.     in all copies or substantial portions of the Software.
  13.  
  14.     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  15.     OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16.     ITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17.     AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18.     LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19.     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  20.     DEALINGS IN THE SOFTWARE.
  21. */
  22.  
  23. // Globals
  24. var _cmIDCount = 0;
  25. var _cmIDName = 'cmSubMenuID';        // for creating submenu id
  26.  
  27. var _cmTimeOut = null;            // how long the menu would stay
  28. var _cmCurrentItem = null;        // the current menu item being selected;
  29.  
  30. var _cmNoAction = new Object ();    // indicate that the item cannot be hovered.
  31. var _cmNoClick = new Object ();        // similar to _cmNoAction but does not respond to mouseup/mousedown events
  32. var _cmSplit = new Object ();        // indicate that the item is a menu split
  33.  
  34. var _cmItemList = new Array ();        // a simple list of items
  35.  
  36. // default node properties
  37. var _cmNodeProperties =
  38. {
  39.       // main menu display attributes
  40.       //
  41.       // Note.  When the menu bar is horizontal,
  42.       // mainFolderLeft and mainFolderRight are
  43.       // put in <span></span>.  When the menu
  44.       // bar is vertical, they would be put in
  45.       // a separate TD cell.
  46.  
  47.       // HTML code to the left of the folder item
  48.       mainFolderLeft: '',
  49.       // HTML code to the right of the folder item
  50.       mainFolderRight: '',
  51.     // HTML code to the left of the regular item
  52.     mainItemLeft: '',
  53.     // HTML code to the right of the regular item
  54.     mainItemRight: '',
  55.  
  56.     // sub menu display attributes
  57.  
  58.     // HTML code to the left of the folder item
  59.     folderLeft: '',
  60.     // HTML code to the right of the folder item
  61.     folderRight: '',
  62.     // HTML code to the left of the regular item
  63.     itemLeft: '',
  64.     // HTML code to the right of the regular item
  65.     itemRight: '',
  66.     // cell spacing for main menu
  67.     mainSpacing: 0,
  68.     // cell spacing for sub menus
  69.     subSpacing: 0,
  70.     // auto disappear time for submenus in milli-seconds
  71.     delay: 200
  72. };
  73.  
  74. //////////////////////////////////////////////////////////////////////
  75. //
  76. // Drawing Functions and Utility Functions
  77. //
  78. //////////////////////////////////////////////////////////////////////
  79.  
  80. //
  81. // produce a new unique id
  82. //
  83. function cmNewID ()
  84. {
  85.     return _cmIDName + (++_cmIDCount);
  86. }
  87.  
  88. //
  89. // return the property string for the menu item
  90. //
  91. function cmActionItem (item, prefix, isMain, idSub, orient, nodeProperties)
  92. {
  93.     // var index = _cmItemList.push (item) - 1;
  94.     _cmItemList[_cmItemList.length] = item;
  95.     var index = _cmItemList.length - 1;
  96.     idSub = (!idSub) ? 'null' : ('\'' + idSub + '\'');
  97.     orient = '\'' + orient + '\'';
  98.     prefix = '\'' + prefix + '\'';
  99.     return ' onmouseover="cmItemMouseOver (this,' + prefix + ',' + isMain + ',' + idSub + ',' + orient + ',' + index + ')" onmouseout="cmItemMouseOut (this,' + nodeProperties.delay + ')" onmousedown="cmItemMouseDown (this,' + index + ')" onmouseup="cmItemMouseUp (this,' + index + ')"';
  100. }
  101.  
  102. //
  103. // this one is used by _cmNoClick to only take care of onmouseover and onmouseout
  104. // events which are associated with menu but not actions associated with menu clicking/closing
  105. //
  106. function cmNoClickItem (item, prefix, isMain, idSub, orient, nodeProperties)
  107. {
  108.     // var index = _cmItemList.push (item) - 1;
  109.     _cmItemList[_cmItemList.length] = item;
  110.     var index = _cmItemList.length - 1;
  111.     idSub = (!idSub) ? 'null' : ('\'' + idSub + '\'');
  112.     orient = '\'' + orient + '\'';
  113.     prefix = '\'' + prefix + '\'';
  114.     return ' onmouseover="cmItemMouseOver (this,' + prefix + ',' + isMain + ',' + idSub + ',' + orient + ',' + index + ')" onmouseout="cmItemMouseOut (this,' + nodeProperties.delay + ')"';
  115. }
  116.  
  117. function cmNoActionItem (item, prefix)
  118. {
  119.     return item[1];
  120. }
  121.  
  122. function cmSplitItem (prefix, isMain, vertical)
  123. {
  124.     var classStr = 'cm' + prefix;
  125.     if (isMain)
  126.     {
  127.         classStr += 'Main';
  128.         if (vertical)
  129.             classStr += 'HSplit';
  130.         else
  131.             classStr += 'VSplit';
  132.     }
  133.     else
  134.         classStr += 'HSplit';
  135.     var item = eval (classStr);
  136.     return cmNoActionItem (item, prefix);
  137. }
  138.  
  139. //
  140. // draw the sub menu recursively
  141. //
  142. function cmDrawSubMenu (subMenu, prefix, id, orient, nodeProperties)
  143. {
  144.     var str = '<div class="' + prefix + 'SubMenu" id="' + id + '"><table summary="sub menu" cellspacing="' + nodeProperties.subSpacing + '" class="' + prefix + 'SubMenuTable">';
  145.     var strSub = '';
  146.  
  147.     var item;
  148.     var idSub;
  149.     var hasChild;
  150.  
  151.     var i;
  152.  
  153.     var classStr;
  154.  
  155.     for (i = 6; i < subMenu.length; ++i)
  156.     {
  157.         item = subMenu[i];
  158.         if (!item)
  159.             continue;
  160.  
  161.         hasChild = (item.length > 6);
  162.         idSub = hasChild ? cmNewID () : null;
  163.  
  164.         str += '<tr class="' + prefix + 'MenuItem"';
  165.         if (item[0] != _cmNoClick)
  166.             str += cmActionItem (item, prefix, 0, idSub, orient, nodeProperties);
  167.         else
  168.             str += cmNoClickItem (item, prefix, 0, idSub, orient, nodeProperties);
  169.         str += '>'
  170.  
  171.         if (item == _cmSplit)
  172.         {
  173.             str += cmSplitItem (prefix, 0, true);
  174.             str += '</tr>';
  175.             continue;
  176.         }
  177.  
  178.         if (item[0] == _cmNoAction || item[0] == _cmNoClick)
  179.         {
  180.             str += cmNoActionItem (item, prefix);
  181.             str += '</tr>';
  182.             continue;
  183.         }
  184.  
  185.         classStr = prefix + 'Menu';
  186.         classStr += hasChild ? 'Folder' : 'Item';
  187.  
  188.         str += '<td class="' + classStr + 'Left">';
  189.  
  190.         if (item[0] != null)
  191.             str += item[0];
  192.         else
  193.             str += hasChild ? nodeProperties.folderLeft : nodeProperties.itemLeft;
  194.  
  195.         str += '<td class="' + classStr + 'Text">' + item[1];
  196.  
  197.         str += '<td class="' + classStr + 'Right">';
  198.  
  199.         if (hasChild)
  200.         {
  201.             str += nodeProperties.folderRight;
  202.             strSub += cmDrawSubMenu (item, prefix, idSub, orient, nodeProperties);
  203.         }
  204.         else
  205.             str += nodeProperties.itemRight;
  206.         str += '</td></tr>';
  207.     }
  208.  
  209.     str += '</table></div>' + strSub;
  210.     return str;
  211. }
  212.  
  213. //
  214. // The function that builds the menu inside the specified element id.
  215. //
  216. // @param    id    id of the element
  217. //        orient    orientation of the menu in [hv][ab][lr] format
  218. //        menu    the menu object to be drawn
  219. //        nodeProperties    properties for each menu node
  220. //
  221. function cmDraw (id, menu, orient, nodeProperties, prefix)
  222. {
  223.     var obj = cmGetObject (id);
  224.  
  225.     if (!nodeProperties)
  226.         nodeProperties = _cmNodeProperties;
  227.     if (!prefix)
  228.         prefix = '';
  229.  
  230.     var str = '<table summary="main menu" class="' + prefix + 'Menu" cellspacing="' + nodeProperties.mainSpacing + '">';
  231.     var strSub = '';
  232.  
  233.     if (!orient)
  234.         orient = 'hbr';
  235.  
  236.     var orientStr = String (orient);
  237.     var orientSub;
  238.     var vertical;
  239.  
  240.     // draw the main menu items
  241.     if (orientStr.charAt (0) == 'h')
  242.     {
  243.         // horizontal menu
  244.         orientSub = 'v' + orientStr.substr (1, 2);
  245.         str += '<tr>';
  246.         vertical = false;
  247.     }
  248.     else
  249.     {
  250.         // vertical menu
  251.         orientSub = 'v' + orientStr.substr (1, 2);
  252.         vertical = true;
  253.     }
  254.  
  255.     var i;
  256.     var item;
  257.     var idSub;
  258.     var hasChild;
  259.  
  260.     var classStr;
  261.  
  262.     for (i = 0; i < menu.length; ++i)
  263.     {
  264.         item = menu[i];
  265.  
  266.         if (!item)
  267.             continue;
  268.  
  269.         str += vertical ? '<tr' : '<td';
  270.         str += ' class="' + prefix + 'MainItem"';
  271.  
  272.         hasChild = (item.length > 6);
  273.         idSub = hasChild ? cmNewID () : null;
  274.  
  275.         str += cmActionItem (item, prefix, 1, idSub, orient, nodeProperties) + '>';
  276.  
  277.         if (item == _cmSplit)
  278.         {
  279.             str += cmSplitItem (prefix, 1, vertical);
  280.             str += vertical? '</tr>' : '</td>';
  281.             continue;
  282.         }
  283.  
  284.         if (item[0] == _cmNoAction || item[0] == _cmNoClick)
  285.         {
  286.             str += cmNoActionItem (item, prefix);
  287.             str += vertical? '</tr>' : '</td>';
  288.             continue;
  289.         }
  290.  
  291.         classStr = prefix + 'Main' + (hasChild ? 'Folder' : 'Item');
  292.  
  293.         str += vertical ? '<td' : '<span';
  294.         str += ' class="' + classStr + 'Left">';
  295.  
  296.         str += (item[0] == null) ? (hasChild ? nodeProperties.mainFolderLeft : nodeProperties.mainItemLeft)
  297.                      : item[0];
  298.         str += vertical ? '</td>' : '</span>';
  299.  
  300.         str += vertical ? '<td' : '<span';
  301.         str += ' class="' + classStr + 'Text">';
  302.         str += item[1];
  303.  
  304.         str += vertical ? '</td>' : '</span>';
  305.  
  306.         str += vertical ? '<td' : '<span';
  307.         str += ' class="' + classStr + 'Right">';
  308.  
  309.         str += hasChild ? nodeProperties.mainFolderRight : nodeProperties.mainItemRight;
  310.  
  311.         str += vertical ? '</td>' : '</span>';
  312.  
  313.         str += vertical ? '</tr>' : '</td>';
  314.  
  315.         if (hasChild)
  316.             strSub += cmDrawSubMenu (item, prefix, idSub, orientSub, nodeProperties);
  317.     }
  318.     if (!vertical)
  319.         str += '</tr>';
  320.     str += '</table>' + strSub;
  321.     obj.innerHTML = str;
  322.     //document.write ("<xmp>" + str + "</xmp>");
  323. }
  324.  
  325. //////////////////////////////////////////////////////////////////////
  326. //
  327. // Mouse Event Handling Functions
  328. //
  329. //////////////////////////////////////////////////////////////////////
  330.  
  331. //
  332. // action should be taken for mouse moving in to the menu item
  333. //
  334. function cmItemMouseOver (obj, prefix, isMain, idSub, orient, index)
  335. {
  336.   var str = '';
  337.  
  338.     clearTimeout (_cmTimeOut);
  339.     
  340.     if (!obj.cmPrefix)
  341.     {
  342.         obj.cmPrefix = prefix;
  343.         obj.cmIsMain = isMain;
  344.     }
  345.  
  346.     var thisMenu = cmGetThisMenu (obj, prefix);
  347.  
  348.     // insert obj into cmItems if cmItems doesn't have obj
  349.     if (!thisMenu.cmItems)
  350.         thisMenu.cmItems = new Array ();
  351.     var i;
  352.     for (i = 0; i < thisMenu.cmItems.length; ++i)
  353.     {
  354.         if (thisMenu.cmItems[i] == obj)
  355.             break;
  356.     }
  357.     if (i == thisMenu.cmItems.length)
  358.     {
  359.         //thisMenu.cmItems.push (obj);
  360.         thisMenu.cmItems[i] = obj;
  361.     }
  362.  
  363.     // hide the previous submenu that is not this branch
  364.     if (_cmCurrentItem)
  365.     {
  366.         // occationally, we get this case when user
  367.         // move the mouse slowly to the border
  368.         if (_cmCurrentItem == thisMenu)
  369.             return;
  370.  
  371.         var thatPrefix = _cmCurrentItem.cmPrefix;
  372.         var thatMenu = cmGetThisMenu (_cmCurrentItem, thatPrefix);
  373.         if (thatMenu != thisMenu.cmParentMenu)
  374.         {
  375.             if (_cmCurrentItem.cmIsMain)
  376.                 str = thatPrefix + 'MainItem';
  377.             else
  378.                 str = thatPrefix + 'MenuItem';
  379.             if (str != _cmCurrentItem.className) _cmCurrentItem.className = str;
  380.             if (thatMenu.id != idSub)
  381.                 cmHideMenu (thatMenu, thisMenu, thatPrefix);
  382.         }
  383.     }
  384.  
  385.     // okay, set the current menu to this obj
  386.     _cmCurrentItem = obj;
  387.  
  388.     // just in case, reset all items in this menu to MenuItem
  389.     cmResetMenu (thisMenu, prefix);
  390.  
  391.     var item = _cmItemList[index];
  392.     var isDefaultItem = cmIsDefaultItem (item);
  393.  
  394.     if (isDefaultItem && item.length>2)    {
  395.         if (item[2] || item.length > 6) {
  396.             if (isMain)
  397.                 str = prefix + 'MainItemHover';
  398.             else
  399.                 str = prefix + 'MenuItemHover';
  400.             if (str != obj.className) obj.className = str;
  401.         }
  402.     }
  403.  
  404.     if (idSub)
  405.     {
  406.         var subMenu = cmGetObject (idSub);
  407.         cmShowSubMenu (obj, prefix, subMenu, orient);
  408.     }
  409.  
  410.     var descript = '';
  411.     if (item.length > 4)
  412.         descript = (item[4] != null) ? item[4] : (item[2] ? item[2] : descript);
  413.     else if (item.length > 2)
  414.         descript = (item[2] ? item[2] : descript);
  415.  
  416.     window.defaultStatus = descript;
  417. }
  418.  
  419. //
  420. // action should be taken for mouse moving out of the menu item
  421. //
  422. function cmItemMouseOut (obj, delayTime)
  423. {
  424.     if (!delayTime)
  425.         delayTime = _cmNodeProperties.delay;
  426.     _cmTimeOut = window.setTimeout ('cmHideMenuTime ()', delayTime);
  427.     window.defaultStatus = '';
  428. }
  429.  
  430. //
  431. // action should be taken for mouse button down at a menu item
  432. //
  433. function cmItemMouseDown (obj, index)
  434. {
  435.     var item = _cmItemList[index];
  436.     if (cmIsDefaultItem (item) && item.length > 2 )    {
  437.         if (item[2] || item.length > 6)    
  438.             if (obj.cmIsMain)
  439.                 obj.className = obj.cmPrefix + 'MainItemActive';
  440.             else
  441.                 obj.className = obj.cmPrefix + 'MenuItemActive';
  442.     }
  443. }
  444.  
  445. //
  446. // action should be taken for mouse button up at a menu item
  447. //
  448. function cmItemMouseUp (obj, index)
  449. {
  450.     var item = _cmItemList[index];
  451.  
  452.     var link = null, target = '_self';
  453.  
  454.     if (item.length > 2)
  455.         link = item[2];
  456.     if (item.length > 3 && item[3])
  457.         target = item[3];
  458.  
  459.     // Tanguy's Confirmation Addon
  460.     if (item.length > 5)
  461.         if (item[5]!='')
  462.             if(confirm(item[5]) == false) link = null;
  463.  
  464.     if (link != null)
  465.     {
  466.         // Tanguy's Firefox fix
  467.         if (window.frames[target]) {
  468.             window.frames[target].location.href=link;
  469.         }    else if (target=='new')
  470.             window.open(link, '_Blank');
  471.         else
  472.             document.location.href=link;
  473.     }
  474.  
  475.     var prefix = obj.cmPrefix;
  476.     var thisMenu = cmGetThisMenu (obj, prefix);
  477.  
  478.     var hasChild = (item.length > 6);
  479.     if (!hasChild)
  480.     {
  481.         if (cmIsDefaultItem (item))
  482.         {
  483.             if (obj.cmIsMain)
  484.                 obj.className = prefix + 'MainItem';
  485.             else
  486.                 obj.className = prefix + 'MenuItem';
  487.         }
  488.         cmHideMenu (thisMenu, null, prefix);
  489.     }
  490.     else
  491.     {
  492.         if (cmIsDefaultItem (item))
  493.         {
  494.             if (obj.cmIsMain)
  495.                 obj.className = prefix + 'MainItemHover';
  496.             else
  497.                 obj.className = prefix + 'MenuItemHover';
  498.         }
  499.     }
  500. }
  501.  
  502. //////////////////////////////////////////////////////////////////////
  503. //
  504. // Mouse Event Support Utility Functions
  505. //
  506. //////////////////////////////////////////////////////////////////////
  507.  
  508. //
  509. // move submenu to the appropriate location
  510. //
  511. // @param    obj    the menu item that opens up the subMenu
  512. //        subMenu    the sub menu to be shown
  513. //        orient    the orientation of the subMenu
  514. //
  515. function cmMoveSubMenu (obj, subMenu, orient)
  516. {
  517.     var mode = String (orient);
  518.     var p = subMenu.offsetParent;
  519.     var subMenuWidth = cmGetWidth (subMenu);
  520.     var horiz = cmGetHorizontalAlign (obj, mode, p, subMenuWidth);
  521.     if (mode.charAt (0) == 'h')
  522.     {
  523.         if (mode.charAt (1) == 'b')
  524.             subMenu.style.top = (-1+cmGetYAt (obj, p) + cmGetHeight (obj)) + 'px';
  525.         else
  526.             subMenu.style.top = (cmGetYAt (obj, p) - cmGetHeight (subMenu)) + 'px';
  527.         if (horiz == 'r')
  528.             subMenu.style.left = (cmGetXAt (obj, p)) + 'px';
  529.         else
  530.             subMenu.style.left = (cmGetXAt (obj, p) + cmGetWidth (obj) - subMenuWidth) + 'px';
  531.     }
  532.     else
  533.     {
  534.         if (horiz == 'r')
  535.             subMenu.style.left = (1+cmGetXAt (obj, p) + cmGetWidth (obj)) + 'px';
  536.         else
  537.             subMenu.style.left = (5+cmGetXAt (obj, p) - subMenuWidth) + 'px';
  538.         if (mode.charAt (1) == 'b')
  539.             subMenu.style.top = (cmGetYAt (obj, p)) + 'px';
  540.         else
  541.             subMenu.style.top = (cmGetYAt (obj, p) + cmGetHeight (obj) - cmGetHeight (subMenu)) + 'px';
  542.     }
  543. }
  544.  
  545. //
  546. // automatically re-adjust the menu position based on available screen size.
  547. //
  548. function cmGetHorizontalAlign (obj, mode, p, subMenuWidth)
  549. {
  550.     var horiz = mode.charAt (2);
  551.     if (!(document.body))
  552.         return horiz;
  553.     var body = document.body;
  554.     var browserLeft;
  555.     var browserRight;
  556.     if (window.innerWidth)
  557.     {
  558.         // DOM window attributes
  559.         browserLeft = window.pageXOffset;
  560.         browserRight = window.innerWidth + browserLeft;
  561.     }
  562.     else if (body.clientWidth)
  563.     {
  564.         // IE attributes
  565.         browserLeft = body.clientLeft;
  566.         browserRight = body.clientWidth + browserLeft;
  567.     }
  568.     else
  569.         return horiz;
  570.     if (mode.charAt (0) == 'h')
  571.     {
  572.         if (horiz == 'r' && (cmGetXAt (obj) + subMenuWidth) > browserRight)
  573.             horiz = 'l';
  574.         if (horiz == 'l' && (cmGetXAt (obj) + cmGetWidth (obj) - subMenuWidth) < browserLeft)
  575.             horiz = 'r';
  576.         return horiz;
  577.     }
  578.     else
  579.     {
  580.         if (horiz == 'r' && (cmGetXAt (obj, p) + cmGetWidth (obj) + subMenuWidth) > browserRight)
  581.             horiz = 'l';
  582.         if (horiz == 'l' && (cmGetXAt (obj, p) - subMenuWidth) < browserLeft)
  583.             horiz = 'r';
  584.         return horiz;
  585.     }
  586. }
  587.  
  588. //
  589. // show the subMenu w/ specified orientation
  590. // also move it to the correct coordinates
  591. //
  592. // @param    obj    the menu item that opens up the subMenu
  593. //        subMenu    the sub menu to be shown
  594. //        orient    the orientation of the subMenu
  595. //
  596. function cmShowSubMenu (obj, prefix, subMenu, orient)
  597. {
  598.     if (!subMenu.cmParentMenu)
  599.     {
  600.         // establish the tree w/ back edge
  601.         var thisMenu = cmGetThisMenu (obj, prefix);
  602.         subMenu.cmParentMenu = thisMenu;
  603.         if (!thisMenu.cmSubMenu)
  604.             thisMenu.cmSubMenu = new Array ();
  605.         //thisMenu.cmSubMenu.push (subMenu);
  606.         thisMenu.cmSubMenu[thisMenu.cmSubMenu.length] = subMenu;
  607.     }
  608.  
  609.     // position the sub menu
  610.     cmMoveSubMenu (obj, subMenu, orient);
  611.     subMenu.style.visibility = 'visible';
  612.  
  613.     //
  614.     // On IE, controls such as SELECT, OBJECT, IFRAME (before 5.5)
  615.     // are window based controls.  So, if the sub menu and these
  616.     // controls overlap, sub menu would be hidden behind them.  Thus
  617.     // one needs to turn the visibility of these controls off when the
  618.     // sub menu is showing, and turn their visibility back on
  619.     // when the sub menu is hiding.
  620.     //
  621.     if (document.all)    // it is IE
  622.     {
  623.         /* part of Felix Zaslavskiy's fix on hiding controls
  624.            not really sure if this part is necessary, but shouldn't
  625.            hurt. */
  626.         if (!subMenu.cmOverlap)
  627.             subMenu.cmOverlap = new Array ();
  628. /*@cc_on @*/
  629. /*@if (@_jscript_version >= 5.5)
  630. @else @*/
  631.         cmHideControl ("IFRAME", subMenu);
  632. /*@end @*/
  633.         cmHideControl ("SELECT", subMenu);
  634.         cmHideControl ("OBJECT", subMenu);
  635.     }
  636. }
  637.  
  638. //
  639. // reset all the menu items to class MenuItem in thisMenu
  640. //
  641. function cmResetMenu (thisMenu, prefix)
  642. {
  643.     if (thisMenu.cmItems)
  644.     {
  645.         var i;
  646.         var str;
  647.         var items = thisMenu.cmItems;
  648.         for (i = 0; i < items.length; ++i)
  649.         {
  650.             if (items[i].cmIsMain)
  651.                 str = prefix + 'MainItem';
  652.             else
  653.                 str = prefix + 'MenuItem';
  654.             if (items[i].className != str)
  655.                 items[i].className = str;
  656.         }
  657.     }
  658. }
  659.  
  660. //
  661. // called by the timer to hide the menu
  662. //
  663. function cmHideMenuTime ()
  664. {
  665.     if (_cmCurrentItem)
  666.     {
  667.         var prefix = _cmCurrentItem.cmPrefix;
  668.         cmHideMenu (cmGetThisMenu (_cmCurrentItem, prefix), null, prefix);
  669.     }
  670. }
  671.  
  672. //
  673. // hide thisMenu, children of thisMenu, as well as the ancestor
  674. // of thisMenu until currentMenu is encountered.  currentMenu
  675. // will not be hidden
  676. //
  677. function cmHideMenu (thisMenu, currentMenu, prefix)
  678. {
  679.     var str = prefix + 'SubMenu';
  680.  
  681.     // hide the down stream menus
  682.     if (thisMenu.cmSubMenu)
  683.     {
  684.         var i;
  685.         for (i = 0; i < thisMenu.cmSubMenu.length; ++i)
  686.         {
  687.             cmHideSubMenu (thisMenu.cmSubMenu[i], prefix);
  688.         }
  689.     }
  690.  
  691.     // hide the upstream menus
  692.     while (thisMenu && thisMenu != currentMenu)
  693.     {
  694.         cmResetMenu (thisMenu, prefix);
  695.         if (thisMenu.className == str)
  696.         {
  697.             thisMenu.style.visibility = 'hidden';
  698.             cmShowControl (thisMenu);
  699.         }
  700.         else
  701.             break;
  702.         thisMenu = cmGetThisMenu (thisMenu.cmParentMenu, prefix);
  703.     }
  704. }
  705.  
  706. //
  707. // hide thisMenu as well as its sub menus if thisMenu is not
  708. // already hidden
  709. //
  710. function cmHideSubMenu (thisMenu, prefix)
  711. {
  712.     if (thisMenu.style.visibility == 'hidden')
  713.         return;
  714.     if (thisMenu.cmSubMenu)
  715.     {
  716.         var i;
  717.         for (i = 0; i < thisMenu.cmSubMenu.length; ++i)
  718.         {
  719.             cmHideSubMenu (thisMenu.cmSubMenu[i], prefix);
  720.         }
  721.     }
  722.     cmResetMenu (thisMenu, prefix);
  723.     thisMenu.style.visibility = 'hidden';
  724.     cmShowControl (thisMenu);
  725. }
  726.  
  727. //
  728. // hide a control such as IFRAME
  729. //
  730. function cmHideControl (tagName, subMenu)
  731. {
  732.     var x = cmGetX (subMenu);
  733.     var y = cmGetY (subMenu);
  734.     var w = subMenu.offsetWidth;
  735.     var h = subMenu.offsetHeight;
  736.  
  737.     var i;
  738.     for (i = 0; i < document.all.tags(tagName).length; ++i)
  739.     {
  740.         var obj = document.all.tags(tagName)[i];
  741.         if (!obj || !obj.offsetParent)
  742.             continue;
  743.  
  744.         // check if the object and the subMenu overlap
  745.  
  746.         var ox = cmGetX (obj);
  747.         var oy = cmGetY (obj);
  748.         var ow = obj.offsetWidth;
  749.         var oh = obj.offsetHeight;
  750.  
  751.         if (ox > (x + w) || (ox + ow) < x)
  752.             continue;
  753.         if (oy > (y + h) || (oy + oh) < y)
  754.             continue;
  755.  
  756.         // if object is already made hidden by a different
  757.         // submenu then we dont want to put it on overlap list of
  758.         // of a submenu a second time.
  759.         // - bug fixed by Felix Zaslavskiy
  760.         if(obj.style.visibility == "hidden")
  761.             continue;
  762.  
  763.         //subMenu.cmOverlap.push (obj);
  764.         subMenu.cmOverlap[subMenu.cmOverlap.length] = obj;
  765.         obj.style.visibility = "hidden";
  766.     }
  767. }
  768.  
  769. //
  770. // show the control hidden by the subMenu
  771. //
  772. function cmShowControl (subMenu)
  773. {
  774.     if (subMenu.cmOverlap)
  775.     {
  776.         var i;
  777.         for (i = 0; i < subMenu.cmOverlap.length; ++i)
  778.             subMenu.cmOverlap[i].style.visibility = "";
  779.     }
  780.     subMenu.cmOverlap = null;
  781. }
  782.  
  783. //
  784. // returns the main menu or the submenu table where this obj (menu item)
  785. // is in
  786. //
  787. function cmGetThisMenu (obj, prefix)
  788. {
  789.     var str1 = prefix + 'SubMenu';
  790.     var str2 = prefix + 'Menu';
  791.     while (obj)
  792.     {
  793.         if (obj.className == str1 || obj.className == str2)
  794.             return obj;
  795.         obj = obj.parentNode;
  796.     }
  797.     return null;
  798. }
  799.  
  800. //
  801. // return true if this item is handled using default handlers
  802. //
  803. function cmIsDefaultItem (item)
  804. {
  805.     if (item == _cmSplit || item[0] == _cmNoAction || item[0] == _cmNoClick)
  806.         return false;
  807.     return true;
  808. }
  809.  
  810. //
  811. // returns the object baring the id
  812. //
  813. function cmGetObject (id)
  814. {
  815.     if (document.all)
  816.         return document.all[id];
  817.     return document.getElementById (id);
  818. }
  819.  
  820. //
  821. // functions that obtain the width of an HTML element.
  822. //
  823. function cmGetWidth (obj)
  824. {
  825.     var width = obj.offsetWidth;
  826.     if (width > 0 || !cmIsTRNode (obj))
  827.         return width;
  828.     if (!obj.firstChild)
  829.         return 0;
  830.     // use TABLE's length can cause an extra pixel gap
  831.     //return obj.parentNode.parentNode.offsetWidth;
  832.  
  833.     // use the left and right child instead
  834.     return obj.lastChild.offsetLeft - obj.firstChild.offsetLeft + cmGetWidth (obj.lastChild);
  835. }
  836.  
  837. //
  838. // functions that obtain the height of an HTML element.
  839. //
  840. function cmGetHeight (obj)
  841. {
  842.     var height = obj.offsetHeight;
  843.     if (height > 0 || !cmIsTRNode (obj))
  844.         return height;
  845.     if (!obj.firstChild)
  846.         return 0;
  847.     // use the first child's height
  848.     return obj.firstChild.offsetHeight;
  849. }
  850.  
  851. //
  852. // functions that obtain the coordinates of an HTML element
  853. //
  854. function cmGetX (obj)
  855. {
  856.     var x = 0;
  857.  
  858.     do
  859.     {
  860.         x += obj.offsetLeft;
  861.         obj = obj.offsetParent;
  862.     }
  863.     while (obj);
  864.     return x;
  865. }
  866.  
  867. function cmGetXAt (obj, elm)
  868. {
  869.     var x = 0;
  870.  
  871.     while (obj && obj != elm)
  872.     {
  873.         x += obj.offsetLeft;
  874.         obj = obj.offsetParent;
  875.     }
  876.     if (obj == elm)
  877.         return x;
  878.     return cmGetX (elm) - x;
  879. }
  880.  
  881. function cmGetY (obj)
  882. {
  883.     var y = 0;
  884.     do
  885.     {
  886.         y += obj.offsetTop;
  887.         obj = obj.offsetParent;
  888.     }
  889.     while (obj);
  890.     return y;
  891. }
  892.  
  893. function cmIsTRNode (obj)
  894. {
  895.     var tagName = obj.tagName;
  896.     return tagName == "TR" || tagName == "tr" || tagName == "Tr" || tagName == "tR";
  897. }
  898.  
  899. //
  900. // get the Y position of the object.  In case of TR element though,
  901. // we attempt to adjust the value.
  902. //
  903. function cmGetYAt (obj, elm)
  904. {
  905.     var y = 0;
  906.  
  907.     if (!obj.offsetHeight && cmIsTRNode (obj))
  908.     {
  909.         var firstTR = obj.parentNode.firstChild;
  910.         obj = obj.firstChild;
  911.         y -= firstTR.firstChild.offsetTop;
  912.     }
  913.  
  914.     while (obj && obj != elm)
  915.     {
  916.         y += obj.offsetTop;
  917.         obj = obj.offsetParent;
  918.     }
  919.  
  920.     if (obj == elm)
  921.         return y;
  922.     return cmGetY (elm) - y;
  923. }
  924.  
  925. //
  926. // debug function, ignore :)
  927. //
  928. function cmGetProperties (obj)
  929. {
  930.     if (obj == undefined)
  931.         return 'undefined';
  932.     if (obj == null)
  933.         return 'null';
  934.  
  935.     var msg = obj + ':\n';
  936.     var i;
  937.     for (i in obj)
  938.         msg += i + ' = ' + obj[i] + '; ';
  939.     return msg;
  940. }
  941.  
  942. /* JSCookMenu v1.3    1. automatically realign (left and right) the submenu when
  943.                        client space is not enough.
  944.                     2. add _cmNoClick to get rid of menu closing behavior
  945.                        on the particular menu item, to make it possible for things
  946.                        such as search box to be inside the menu.
  947. */
  948. /* JSCookMenu v1.25    1. fix Safari positioning issue.  The problem is that all TR elements are located
  949.                        at the top left corner.  Thus, need to obtain the "virtual"
  950.                        position of these element could be at.
  951. */
  952. /* JSCookMenu v1.0.        (c) Copyright 2002 by Heng Yuan */
  953.